from typing import List
from collections import Counter
from functools import reduce
from math import gcd

class Solution:
    def hasGroupsSizeX(self, deck: List[int]) -> bool:
        vals = Counter(deck).values()
        return reduce(gcd, vals) >= 2



s = Solution()
print(s.hasGroupsSizeX([1,2,3,4,4,3,2,1]))
print(s.hasGroupsSizeX([1, 2, 2, 4, 4, 3, 2, 1]))
